package com.wandian.core.allUtils
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	
	public class LoadObj extends EventDispatcher
	{
		private static var _instance:LoadObj;
		private var _url:String
		private var _type:String
		private var _loader:Object
		private var _loadInfo:Object
		private var _fun:Function
		public function LoadObj()
		{
		}
		public static function get instance():LoadObj
		{
			if(_instance == null)
			{
				_instance = new LoadObj();
			}
			return _instance;
		}
		public function loadMedia(url:String,fun:Function=null):void{
			_fun=fun;
			_loader=new Loader
			_loader.load(new URLRequest(url));
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadMediaComplete)
		}
		public function loadtextdata(url:String,fun:Function=null):void{
			_fun=fun;
			_loader=new URLLoader
			_loader.load(new URLRequest(url));
			_loader.addEventListener(Event.COMPLETE,loadTextdataComplete)
		}
		private function loadMediaComplete(e:Event):void{
			_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,loadMediaComplete)
			var obj:Object=new Object
			_loadInfo=e.currentTarget
			obj.info=_loadInfo
			dispatchEvent(new LoadEvt(LoadEvt.LOAD_COMPLETE,obj))
			if(_fun!=null){
				_fun(obj);
			}
		}
		private function loadTextdataComplete(e:Event):void{
			_loader.removeEventListener(Event.COMPLETE,loadTextdataComplete)
			var obj:Object=new Object
			_loadInfo=e.currentTarget.data
			obj.info=_loadInfo
			dispatchEvent(new LoadEvt(LoadEvt.LOAD_COMPLETE,obj))
			if(_fun!=null){
				_fun(obj);
			}
		}
	}
}